$().ready(function() {
	validateRule();

	$("input[name=type]").click(function(){
		var type = $("input[name=type]:checked").val();
		getPriceRuleList(type);
	});
});

$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});

function getPriceRuleList(type) {
	$.ajax({
		cache : true,
		type : "GET",
		url : "/car/carInfo/getPriceRuleList",
		data : {
			type : type
		},
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				var html = '';
				if(data.msg != null){
					for(var i=0; i<data.msg.length; i++){
						html += '<option  value="'+ data.msg[i].id +'">'+ data.msg[i].amt +'元</option>';
					}
				}
				$("#priceId").html(html);
			} else {
				parent.layer.alert(data.msg)
			}

		}
	});
}


function update() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/car/carInfo/update",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});
}


function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			amt : {
				required : true
			}
		},
		messages : {
			amt : {
				required : icon + "单价必填"
			}
		}
	})
}

function changeRule(type){
    $("#monthDiv").hide();
    $("#yearDiv").hide();
    $("#seasonDiv").hide();
	if(type == 1){
        $("#monthDiv").show();
	}else if(type == 2){
        $("#seasonDiv").show();
    }else if(type == 3){
        $("#yearDiv").show();
    }
}